package com.tanzeer.deliverytracker.adapter;

import java.util.List;

import com.tanzeer.deliverytracker.R;
import com.tanzeer.deliverytracker.utils.CommonConstants;

import android.R.bool;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NavDrawerAdapter extends ArrayAdapter<String> {

	public Context context;

	public NavDrawerAdapter(Context context, int textViewResourceId,
			List<String> items) {
		super(context, textViewResourceId, items);
		Log.e("msg", "" + items.size());
		this.context = context;

	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public int getItemViewType(int position) {

		if (position == 0 || position == 3)
			return 0;
		else
			return 1;
	}

	private class ViewHolder {

		TextView name;
		ImageView icons;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		String obj = getItem(position);
		boolean check = true;
		if (obj.equals("By Status"))
			check = false;
		if (obj.equals("By Category"))
			check = false;
		if (convertView == null) {
			int type = getItemViewType(position);
			if (type == 0) {

				convertView = mInflater.inflate(R.layout.navdraweroprow, null);
				holder = new ViewHolder();
				holder.name = (TextView) convertView
						.findViewById(R.id.textViewopmaster);

				convertView.setTag(holder);

			} else {

				convertView = mInflater.inflate(R.layout.nav_drawer_row, null);
				holder = new ViewHolder();
				holder.name = (TextView) convertView
						.findViewById(R.id.textViewop);
				holder.icons = (ImageView) convertView
						.findViewById(R.id.imageView1);
				convertView.setTag(holder);

			}

		} else
			holder = (ViewHolder) convertView.getTag();

		if (position == 0 || position == 3) {
			if (holder.name == null) {
				Log.e("msg", "null");
				
			}
			String opName = getItem(position);
			holder.name.setText(opName);
			
			convertView.setFocusable(false);
			convertView.setClickable(false);

		} else {
			// Log.v("msg","hello");
			String opName = getItem(position);

			holder.name.setText(opName);
			if (position == 1)
				holder.icons
						.setBackgroundResource(R.drawable.ic_action_navigation_refresh);
			else if (position == 2)
				holder.icons
						.setBackgroundResource(R.drawable.ic_action_navigation_accept);
			else if (opName.equals("Incoming")) {
				holder.icons.setBackgroundResource(R.drawable.incoming);
			} else if (opName.equals("Outgoing")) {
				holder.icons.setBackgroundResource(R.drawable.outgoing);
			} else if (opName.equals("Favorite")) {
				holder.icons.setBackgroundResource(R.drawable.favorite);
			} else if (opName.equals("Movie")) {
				holder.icons.setBackgroundResource(R.drawable.film_reel);
			} else if (opName.equals("Gift")) {
				holder.icons.setBackgroundResource(R.drawable.present);
			} else if (opName.equals("Heart")) {
				holder.icons.setBackgroundResource(R.drawable.heart);
			} else if (opName.equals("Business")) {
				holder.icons.setBackgroundResource(R.drawable.business);
			} else if (opName.equals("Important")) {
				holder.icons.setBackgroundResource(R.drawable.important);
			} else if (opName.equals("Camera")) {
				holder.icons.setBackgroundResource(R.drawable.camera_unmount2);
			} else if (opName.equals("Clothes")) {
				holder.icons.setBackgroundResource(R.drawable.clothes);
			} else if (opName.equals("Computer")) {
				holder.icons.setBackgroundResource(R.drawable.mycomputer);
			} else if (opName.equals("Games")) {
				holder.icons.setBackgroundResource(R.drawable.gaming_pad);
			} else if (opName.equals("Food Dishes")) {
				holder.icons.setBackgroundResource(R.drawable.fooddishes);
			} else if (opName.equals("Light")) {
				holder.icons.setBackgroundResource(R.drawable.light);
			} else if (opName.equals("Music")) {
				holder.icons.setBackgroundResource(R.drawable.kbemusedsrv);
			} else if (opName.equals("Office Materials")) {
				holder.icons.setBackgroundResource(R.drawable.office);
			} else if (opName.equals("Paint")) {
				holder.icons.setBackgroundResource(R.drawable.kolourpaint);
			} else if (opName.equals("Medicine")) {
				holder.icons.setBackgroundResource(R.drawable.pill);
			} else if (opName.equals("Flowers")) {
				holder.icons.setBackgroundResource(R.drawable.flowers);
			} else if (opName.equals("Sports")) {
				holder.icons.setBackgroundResource(R.drawable.sports);
			} else if (opName.equals("Tools")) {
				holder.icons.setBackgroundResource(R.drawable.tool2);
			} else if (opName.equals("None")) {
				holder.icons.setBackgroundResource(R.drawable.white);
			}

		}


		return convertView;

	}

}
